﻿using Microsoft.Extensions.Options;
using RuoVea.ExFilter.Domain;
using RuoVea.ExSugar;
using RuoVea.OmiApi.Log;

namespace RuoVea.OmiApi.Template.Entry.Filters;
/// <summary>
/// 
/// </summary>
public class CustomizeFilterLog : ICustomizeFilterLog
{
    /// <summary>
    /// 
    /// </summary>
    /// <param name="dbConnection"></param>
    public CustomizeFilterLog(IOptions<List<DbConnectionConfig>> dbConnection) : base(dbConnection) { }

    /// <summary>
    /// 操作日志
    /// </summary>
    /// <param name="operation"></param>
    /// <returns></returns>
    public override bool LogOp(OperationVo operation)
    {
        List<string> ignoreUrls = new List<string> { "Submit", "DeleteAsync"
        , "DeleteAsync"
        , "UpdateUser"
        , "AddAsync"
        , "ChangeUserStatus"
        , "UpdateUserInfo"
        , "UpdateUserPwd"
        , "ResetUserPwd"
        };
        return ignoreUrls.Contains(operation.ActionName, StringComparer.OrdinalIgnoreCase);
    }

    /// <summary>
    /// 访问日志
    /// </summary>
    /// <param name="operation"></param>
    /// <returns></returns>
    public override bool LogVis(OperationVo operation)
    {
        if (operation.Url.Contains("/auth/login", StringComparison.OrdinalIgnoreCase) && "post".Equals(operation.RequestType, StringComparison.OrdinalIgnoreCase))
            return true;
        else if (operation.Url.Contains("/auth/logout", StringComparison.OrdinalIgnoreCase))
            return true;
        return false;
    }
}